import {
  login,
  getClassify,
  getOrder,
  getOrderCount,
  getDeleteList,
  getCancel,
  getPayament
} from '@/services'
import { setToken } from '@/utils';
import {getCode} from "../../services/modules/user"
const state = {
  info: {},
  orderCount:{},
  classifyList:[],
  orderList:[],
  payamentList:{}
};

const getters = {};

const mutations = {
  update(state, payload){
    for (let key in payload) {
      state[key] = payload[key];
    }
  }
};
// 登录
const actions = {
  async login({commit}, payload) {
    let result = await login(payload);
    if (result){
      commit('update', {info: result});
      setToken(result.access_token);
    }
  },
  async getCodeNumber({commit},payload){
    let result = await getCode({mobile:payload})
  },
  //获取订单数
  async getOrderCount({commit}){
    let result = await getOrderCount()
    if(result){
        commit("update",{orderCount:result})
    }
},
  // 我的收藏数据
  async getActionsClassify({commit},payload){
    const result = await getClassify(payload)
    if(result){
      commit('update', {classifyList: result.records})
    }
  },
  // 获取订单列表数据
  async getActionsOrder({commit},payload){
    const result = await getOrder(payload)
    if(result){
      commit('update',{orderList:result.records})
    }
  },
  //删除订单
  async getActionsDelete({commit},payload){
    const result = await getDeleteList(payload)
  },
  // 取消订单
  async getActionsCancel({commit},payload){
    const result = await getCancel(payload)
  },
  // 付款
async getActionsPayament({commit},payload){
  const result = await getPayament(payload)
  if(result){
    commit('update',{payamentList:result})
    
  }
}
};

export default {
  namespaced: true,
  modules: {},
  state,
  getters,
  mutations,
  actions,
}